namespace CoreManager.MessageQueue.Models;

/// <summary>
/// Kafka配置选项
/// </summary>
public class KafkaOptions
{
    public const string SectionName = "Kafka";
    
    /// <summary>
    /// Kafka服务器地址
    /// </summary>
    public string BootstrapServers { get; set; } = "localhost:9092";
    
    /// <summary>
    /// 生产者配置
    /// </summary>
    public ProducerOptions Producer { get; set; } = new();
    
    /// <summary>
    /// 消费者配置
    /// </summary>
    public ConsumerOptions Consumer { get; set; } = new();
    
    /// <summary>
    /// 主题配置
    /// </summary>
    public TopicOptions Topics { get; set; } = new();
}

/// <summary>
/// 生产者配置选项
/// </summary>
public class ProducerOptions
{
    /// <summary>
    /// 消息确认模式
    /// </summary>
    public string Acks { get; set; } = "all";
    
    /// <summary>
    /// 重试次数
    /// </summary>
    public int Retries { get; set; } = 3;
    
    /// <summary>
    /// 批次大小
    /// </summary>
    public int BatchSize { get; set; } = 16384;
    
    /// <summary>
    /// 压缩类型
    /// </summary>
    public string CompressionType { get; set; } = "snappy";
}

/// <summary>
/// 消费者配置选项
/// </summary>
public class ConsumerOptions
{
    /// <summary>
    /// 消费者组ID
    /// </summary>
    public string GroupId { get; set; } = "coremanager-consumer-group";
    
    /// <summary>
    /// 自动提交偏移量
    /// </summary>
    public bool EnableAutoCommit { get; set; } = true;
    
    /// <summary>
    /// 自动提交间隔
    /// </summary>
    public int AutoCommitIntervalMs { get; set; } = 1000;
    
    /// <summary>
    /// 偏移量重置策略
    /// </summary>
    public string AutoOffsetReset { get; set; } = "latest";
}

/// <summary>
/// 主题配置选项
/// </summary>
public class TopicOptions
{
    /// <summary>
    /// 核心管理事件主题
    /// </summary>
    public string CoreManagerEvents { get; set; } = "coremanager-events";
    
    /// <summary>
    /// 系统通知主题
    /// </summary>
    public string SystemNotifications { get; set; } = "system-notifications";
    
    /// <summary>
    /// 用户活动主题
    /// </summary>
    public string UserActivities { get; set; } = "user-activities";
    
    /// <summary>
    /// 系统事件主题
    /// </summary>
    public string SystemEvents { get; set; } = "system-events";
    
    /// <summary>
    /// 自定义主题列表（用于后台服务自动订阅）
    /// </summary>
    public List<string> CustomTopics { get; set; } = new();
    
    /// <summary>
    /// 获取所有需要订阅的主题
    /// </summary>
    /// <returns></returns>
    public List<string> GetAllSubscriptionTopics()
    {
        var topics = new List<string>
        {
            CoreManagerEvents,
            SystemNotifications,
            UserActivities,
            SystemEvents
        };
        
        // 添加自定义主题
        if (CustomTopics != null && CustomTopics.Any())
        {
            topics.AddRange(CustomTopics);
        }
        
        return topics.Distinct().ToList();
    }
}
